package com.yanqu.road.server.cmd.activity.feast;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ShanHeFeastProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.feast.CrossFeastMgr;
import com.yanqu.road.server.manager.activity.feast.activity.CrossFeastActivity;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;

@Cmd(code = CrossProtocol.C_CROSS_SHAN_HE_FEAST_GET_ACTIVITY_DATA, desc = "跨服取下活动数据")
public class CrossFeastGetActivityDataCmd extends CrossCommand {

    private int activityId;

    private long userId;

    ShanHeFeastProto.CrossFeastGetActivityDataReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = ShanHeFeastProto.CrossFeastGetActivityDataReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        // 更新userBaseInfo
        UserBaseInfo userBaseInfo = PlayerBasePb.parseBaseUserInfo(reqMsg.getUserBaseInfo());
        CrossUserMgr.updateUserBaseInfo(userId, userBaseInfo);

        CrossFeastActivity activity = CrossFeastMgr.getActivity(activityId);
        if (activity == null) {
            ret = GameErrorCode.E_SHAN_HE_FEAST_ACTIVITY_NOT_FOUND;
            return;
        }
        ret = activity.getActivityData(userId);
    }

    @Override
    public void sendData() {

    }
}
